//
//  WorkListController.m
//  Ten
//
//  Created by anfuer on 2018/10/31.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "WorkListController.h"
#import "WorkCell.h"
#import "AddWorkController.h"
#import "AddjiaoyuController.h"
#import "AddmyProjectController.h"
@interface WorkListController ()

@property (weak, nonatomic) IBOutlet UITableView *tbv;
@property (weak, nonatomic) IBOutlet UILabel *lb1;
@property (weak, nonatomic) IBOutlet UIButton *btno;

@end

@implementation WorkListController

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([_type isEqualToString:@"jiaoyu"]) {
        _lb1.text=@"教育经历";
        [_btno setTitle:@"新增教育经历" forState:UIControlStateNormal];
    }else if ([_type isEqualToString:@"xiangmu"])
    {
        _lb1.text=@"项目经验";
        [_btno setTitle:@"新增项目经验" forState:UIControlStateNormal];
    }
    // Do any additional setup after loading the view.
}




- (IBAction)AddBtna:(UIButton *)sender {
    if ([[sender currentTitle]isEqualToString:@"新增教育经历"]) {
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"jl" bundle:nil];
        AddjiaoyuController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Addjiaoyu"];
        secondViewController.resume_id=_resume_id;
        [self.navigationController pushViewController:secondViewController animated:YES];
        
        
    }else if ([[sender currentTitle]isEqualToString:@"新增项目经验"])
    {
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"jl" bundle:nil];
        AddmyProjectController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"AddmyProject"];
        secondViewController.resume_id=_resume_id;
        [self.navigationController pushViewController:secondViewController animated:YES];

    }
    else
    {
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"jl" bundle:nil];
        AddWorkController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"AddWork"];
        secondViewController.resume_id=_resume_id;
        [self.navigationController pushViewController:secondViewController animated:YES];
    }
  
 
}

#pragma mark 返回分组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _tbvdata.count;
}

#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    WorkCell*cell=[WorkCell CellWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell Cellinit:_tbvdata[indexPath.section] Andresume_id:@""];
    return cell;
}
#pragma mark 设置分组头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}


#pragma mark 设置尾部说明内容高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 160;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
//    delete_work_experience
}


//设置滑动时显示多个按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
    //添加一个删除按钮
    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDestructive) title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        
        NSDictionary*dic= _tbvdata[indexPath.section];
        [FuncPublic getData:self parameters:@{@"id":WXGStr(dic[@"id"])} RequestUrl:[_type isEqualToString:@"work"]?delete_work_experience:[_type isEqualToString:@"xiangmu"]?delete_projects:delete_educationals success:^(NSDictionary *acountInfo) {
            [_tbvdata removeObjectAtIndex:indexPath.section];
            [_tbv reloadData];
        }];

    }];
    //删除按钮颜色
    deleteAction.backgroundColor = [UIColor redColor];
    
    return @[deleteAction];
    
}

@end
